package com.dnjn.happiness.system.api.factory;

import com.dnjn.happiness.common.core.domain.R;
import com.dnjn.happiness.common.core.model.SysSiteVO;
import com.dnjn.happiness.system.api.RemoteSiteService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;


@Component
public class RemoteSiteFallbackFactory implements FallbackFactory<RemoteSiteService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteSiteFallbackFactory.class);

    @Override
    public RemoteSiteService create(Throwable throwable) {
        log.error("调用厂区微服务失败：{}" + throwable.getMessage());
        return new RemoteSiteService() {
            @Override
            public R<SysSiteVO> getInfoById(Long siteId, String source) {
                return R.fail("查询厂区信息失败：{}" + throwable.getMessage());
            }

            @Override
            public R<List<SysSiteVO>> getSiteList(String source) {
                return R.fail("查询厂区信息失败：{}" + throwable.getMessage());
            }
        };
    }
}
